﻿using System;
using System.Windows;
using System.Windows.Markup;

namespace HSS.Xaml.UI.Controls
{
	/// <summary>
	/// A Control Utility class
	/// </summary>
	internal static class ControlUtil
	{
		/// <summary>
		/// Generate a simple DataTemplate
		/// </summary>
		/// <param name="type">The Type of the Control contained in the DataTemplate</param>
		/// <param name="BindingElementName">The DataContext Object Property to Bind to</param>
		/// <returns>The DataTemplate</returns>
		public static DataTemplate CreateDataTemplate(Type type, string BindingElementName)
		{
			return (DataTemplate)XamlReader.Load(
					@"<DataTemplate xmlns=""http://schemas.microsoft.com/client/2007"">
						<" + type.Name + @" Text=""{Binding " + BindingElementName + @"}""/>
					</DataTemplate>");
		}

		/// <summary>
		/// Compare to Property values
		/// </summary>
		/// <param name="value1">The first value to compare</param>
		/// <param name="value2">The second value to compare</param>
		/// <returns>true if they are  the same; otherwise false</returns>
		public static bool AreValuesEqual(object value1, object value2)
		{
			bool flag = value1 == value2;
			if (!flag && (value1 != null))
				flag = value1.Equals(value2);
			return flag;
		}
	}
}
